/**
 * 
 */
package games;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.UIManager;

/**
 * @author Owner
 *
 */
public abstract class PassNumberGame extends Game {
	/**
	 * 
	 */
	private static final long serialVersionUID=1L;	
	
	String GAME_NAME;
	
	protected static final int NUMBER=0;
	protected static final int GO=1;
	public static final Font SELECTED_FONT=new Font(Font.SERIF,Font.ITALIC,80);
	public static final Font FONT=new Font(Font.SERIF,Font.BOLD,60);
	protected static final int FRAME_WIDTH=600;
	protected static final int FRAME_HEIGHT=500;
	protected static final int HEADER_HEIGHT=160;
	
	/*
	 * 	private static final String[] firstLine={"Ultimatum: You are Player 1.",
																		"Dictator: You are Player 1.",
																		"Trust: You are Player 2.",
																		"Trust: You are Player 1."};
	private static final String[] secondLine={"Player 2 can accept or decline what you offer.",
																		"Player 2 must accept what you offer.",
																		"Multiplication factor: %d, Player 1 gave $%d.",
																		"What you offer Player 2 will be multiplied by: %d."};
	private static final String thirdLine="You can offer $%d. How much will you offer?";
	 */
	

	int start;
	int maximum;
	int factor;
	int number;
	int player;
	String str;
	int selected;
	FontMetrics fm=getFontMetrics(FONT);
	FontMetrics sfm=getFontMetrics(SELECTED_FONT);
	FontMetrics hfm=getFontMetrics(HEADER_FONT);
	NumberPainter painter=new NumberPainter();
	HeaderPainter headerPainter;

	public PassNumberGame(Runner runner, String gameName) {
		super(runner,gameName);
	}
	
	public void init() {
		// Turn off metal's use of bold fonts
		UIManager.put("swing.boldMetal",Boolean.FALSE);
	}

	public void start() {
		initComponents();
	}
	
	public abstract void initComponents();
	
	class HeaderPainter extends Component {
		
		/**
		 * 
		 */
		private static final long serialVersionUID=1L;
		String s1;
		String s2;
		String s3;
		
		public HeaderPainter(String s1) {
			this(s1,"","");
		}
		
		public HeaderPainter(String s1,String s2) {
			this(s1,"",s2);
		}
		
		public HeaderPainter(String s1,String s2,String s3) {
			this.s1=s1;
			this.s2=s2;
			this.s3=s3;
		}
		
	  public Dimension getPreferredSize(){
	    return new Dimension(WIDTH,HEADER_HEIGHT);
		}
	  
	  public void paint(Graphics g) {
	    int cWidth=getWidth();
	    int height=hfm.getHeight();
	    g.setFont(HEADER_FONT);
	    
	    //draw the header	    
	    int width=(hfm.stringWidth(s1));
	    g.drawString(s1,(cWidth-width)/2,height);

	    width=(hfm.stringWidth(s2));
	    g.drawString(s2,(cWidth-width)/2,height*2);

	    width=(hfm.stringWidth(s3));
	    g.drawString(s3,(cWidth-width)/2,height*3);
		}
	}
	
	class NumberPainter extends Component {
		/**
		 * 
		 */
		private static final long serialVersionUID=1L;
		BufferedImage img = null;
		
	  public Dimension getPreferredSize(){
	    return new Dimension(FRAME_WIDTH,FRAME_HEIGHT-headerPainter.getHeight());
		}
	  
	  public void paint(Graphics g) {
	    //Dimension size = getSize();
	    int cWidth=getWidth();
	    
	    //draw the number
	    int width=(selected==NUMBER?sfm.stringWidth(str):fm.stringWidth(str));
	    g.setFont(selected==NUMBER?SELECTED_FONT:FONT);
	    g.setColor(selected==NUMBER?Color.RED:Color.BLACK);
	    g.drawString(str,(cWidth-width)/2,100);
	    
	    //draw the continue image
			img=loadImage(selected==GO?"selectedGo":"go");
      g.drawImage(img,400,150,null);
		}
	}

}
